from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-26 14:12:51.727354
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 26, Aug, 2021
Time: 14:13:07
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.8069
Nobs: 395.000 HQIC: -46.3543
Log likelihood: 4271.59 FPE: 5.15971e-21
AIC: -46.7135 Det(Omega_mle): 4.12006e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.435424 0.095059 4.581 0.000
L1.Burgenland 0.104999 0.049111 2.138 0.033
L1.Kärnten -0.115840 0.024481 -4.732 0.000
L1.Niederösterreich 0.158552 0.106323 1.491 0.136
L1.Oberösterreich 0.136155 0.104061 1.308 0.191
L1.Salzburg 0.281013 0.051552 5.451 0.000
L1.Steiermark 0.028189 0.068435 0.412 0.680
L1.Tirol 0.110217 0.053920 2.044 0.041
L1.Vorarlberg -0.117093 0.048805 -2.399 0.016
L1.Wien -0.014894 0.093966 -0.159 0.874
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.019387 0.220726 0.088 0.930
L1.Burgenland -0.043088 0.114035 -0.378 0.706
L1.Kärnten 0.035581 0.056844 0.626 0.531
L1.Niederösterreich -0.250696 0.246881 -1.015 0.310
L1.Oberösterreich 0.530891 0.241630 2.197 0.028
L1.Salzburg 0.311413 0.119704 2.602 0.009
L1.Steiermark 0.115664 0.158906 0.728 0.467
L1.Tirol 0.308774 0.125203 2.466 0.014
L1.Vorarlberg -0.009406 0.113325 -0.083 0.934
L1.Wien -0.006865 0.218189 -0.031 0.975
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.248951 0.048072 5.179 0.000
L1.Burgenland 0.089363 0.024836 3.598 0.000
L1.Kärnten -0.003266 0.012380 -0.264 0.792
L1.Niederösterreich 0.222697 0.053768 4.142 0.000
L1.Oberösterreich 0.167098 0.052624 3.175 0.001
L1.Salzburg 0.037712 0.026070 1.447 0.148
L1.Steiermark 0.012075 0.034608 0.349 0.727
L1.Tirol 0.069746 0.027268 2.558 0.011
L1.Vorarlberg 0.057148 0.024681 2.315 0.021
L1.Wien 0.099659 0.047519 2.097 0.036
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181808 0.047209 3.851 0.000
L1.Burgenland 0.045369 0.024390 1.860 0.063
L1.Kärnten -0.007140 0.012158 -0.587 0.557
L1.Niederösterreich 0.134490 0.052803 2.547 0.011
L1.Oberösterreich 0.315779 0.051680 6.110 0.000
L1.Salzburg 0.098940 0.025603 3.864 0.000
L1.Steiermark 0.137118 0.033987 4.034 0.000
L1.Tirol 0.074812 0.026779 2.794 0.005
L1.Vorarlberg 0.054853 0.024238 2.263 0.024
L1.Wien -0.036485 0.046667 -0.782 0.434
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.213373 0.094010 2.270 0.023
L1.Burgenland -0.060532 0.048569 -1.246 0.213
L1.Kärnten -0.036050 0.024211 -1.489 0.136
L1.Niederösterreich 0.098818 0.105149 0.940 0.347
L1.Oberösterreich 0.185350 0.102913 1.801 0.072
L1.Salzburg 0.258486 0.050983 5.070 0.000
L1.Steiermark 0.080912 0.067680 1.196 0.232
L1.Tirol 0.123113 0.053325 2.309 0.021
L1.Vorarlberg 0.112802 0.048266 2.337 0.019
L1.Wien 0.027786 0.092929 0.299 0.765
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.025429 0.073159 0.348 0.728
L1.Burgenland 0.026057 0.037797 0.689 0.491
L1.Kärnten 0.050388 0.018841 2.674 0.007
L1.Niederösterreich 0.201628 0.081828 2.464 0.014
L1.Oberösterreich 0.343937 0.080088 4.294 0.000
L1.Salzburg 0.046876 0.039676 1.181 0.237
L1.Steiermark -0.000834 0.052669 -0.016 0.987
L1.Tirol 0.114223 0.041498 2.752 0.006
L1.Vorarlberg 0.061148 0.037562 1.628 0.104
L1.Wien 0.132456 0.072319 1.832 0.067
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189236 0.089146 2.123 0.034
L1.Burgenland 0.021527 0.046056 0.467 0.640
L1.Kärnten -0.057425 0.022958 -2.501 0.012
L1.Niederösterreich -0.127145 0.099709 -1.275 0.202
L1.Oberösterreich 0.193948 0.097589 1.987 0.047
L1.Salzburg 0.029212 0.048346 0.604 0.546
L1.Steiermark 0.302271 0.064179 4.710 0.000
L1.Tirol 0.493151 0.050566 9.753 0.000
L1.Vorarlberg 0.067125 0.045769 1.467 0.142
L1.Wien -0.109039 0.088121 -1.237 0.216
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161406 0.097113 1.662 0.097
L1.Burgenland -0.005251 0.050172 -0.105 0.917
L1.Kärnten 0.063230 0.025010 2.528 0.011
L1.Niederösterreich 0.197780 0.108620 1.821 0.069
L1.Oberösterreich -0.119584 0.106310 -1.125 0.261
L1.Salzburg 0.242371 0.052666 4.602 0.000
L1.Steiermark 0.153074 0.069914 2.189 0.029
L1.Tirol 0.050113 0.055085 0.910 0.363
L1.Vorarlberg 0.121383 0.049860 2.434 0.015
L1.Wien 0.138717 0.095996 1.445 0.148
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.489658 0.052784 9.277 0.000
L1.Burgenland -0.010826 0.027270 -0.397 0.691
L1.Kärnten -0.009902 0.013594 -0.728 0.466
L1.Niederösterreich 0.200884 0.059039 3.403 0.001
L1.Oberösterreich 0.261142 0.057783 4.519 0.000
L1.Salzburg 0.019566 0.028626 0.684 0.494
L1.Steiermark -0.024033 0.038001 -0.632 0.527
L1.Tirol 0.069325 0.029941 2.315 0.021
L1.Vorarlberg 0.059415 0.027100 2.192 0.028
L1.Wien -0.052542 0.052177 -1.007 0.314
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.017991 0.080541 0.134536 0.128433 0.042708 0.067987 0.003602 0.174221
Kärnten 0.017991 1.000000 -0.058830 0.129217 0.046617 0.069205 0.457338 -0.094004 0.097171
Niederösterreich 0.080541 -0.058830 1.000000 0.283633 0.088655 0.273987 0.012077 0.148142 0.249660
Oberösterreich 0.134536 0.129217 0.283633 1.000000 0.177834 0.289104 0.159569 0.117408 0.139554
Salzburg 0.128433 0.046617 0.088655 0.177834 1.000000 0.127377 0.054394 0.110055 0.050996
Steiermark 0.042708 0.069205 0.273987 0.289104 0.127377 1.000000 0.125998 0.088009 -0.024810
Tirol 0.067987 0.457338 0.012077 0.159569 0.054394 0.125998 1.000000 0.041346 0.117435
Vorarlberg 0.003602 -0.094004 0.148142 0.117408 0.110055 0.088009 0.041346 1.000000 -0.045599
Wien 0.174221 0.097171 0.249660 0.139554 0.050996 -0.024810 0.117435 -0.045599 1.000000